<template>
  <div>
    <label>日期:</label>
    <el-date-picker v-model="newDate"
                    value-format="yyyy-MM-dd"
                    format="yyyy-MM-dd"
                    placeholder="选择日期"></el-date-picker>
    <div>
      <label>体重:</label>
      <el-input type="number" v-model="newWeight" placeholder="输入体重"></el-input>
    </div>
    <el-button type="primary" @click="addNewRecord">提交</el-button>
  </div>
</template>

<script>
import dayjs from 'dayjs';
import DataAccess from "@/functions/DataAccess";

export default {
  name: "AddNewRecord",
  data: function () {
    return {
      newWeight: 100,
      newDate: dayjs().format('YYYY-MM-DD')
    }
  },
  methods: {
    addNewRecord: function () {
      DataAccess.addNewRecord(this.newDate, this.newWeight).then(() => {
        //成功后触发重新加载数据事件
        this.$emit('reload-data')
      }).catch({});
    }
  }
}
</script>

<style scoped>

</style>